package org.six11.olive3.picturephone;

import java.io.PrintWriter;

import org.six11.olive3.net.Message;
import org.six11.olive3.net.MessageHandler;

/**
 * 
 * 
 * @author Gabe Johnson <johnsogg@cmu.edu>
 */
public abstract class AWTMessageHandler extends MessageHandler {

  public void awtHandleLater(Message m) { }

  public void awtHandleNow(Message m, PrintWriter out) { }

  public void handleLater(final Message m) {
    Runnable r = new Runnable() {
      public void run() {
        awtHandleLater(m);
      }
    };
    javax.swing.SwingUtilities.invokeLater(r);
  }

  public void handleNow(final Message m, final PrintWriter out) {
    Runnable r = new Runnable() {
      public void run() {
        awtHandleNow(m, out);
      }
    };
    try {
      javax.swing.SwingUtilities.invokeAndWait(r);
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }

}
